import {Component, Input, OnInit} from '@angular/core';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {Encapsulation} from "../../../../model/Encapsulation";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-sortingedit',
  templateUrl: './sortingedit.component.html',
  styleUrls: ['./sortingedit.component.css']
})
export class SortingeditComponent implements OnInit {
  @Input() id: string
  e: Encapsulation
  fzArray: Array<any>
  zjArray: Array<any>
  proidArray: Array<any>
  ckglyArray: Array<any>

  constructor(private adminService: AdminService,
              private alertService: AlertService,
              private authService:AuthService) {
    this.e = new Encapsulation();
    this.fzArray = new Array();
    this.zjArray = new Array();
    this.proidArray = new Array();
    this.ckglyArray = new Array();
  }

  ngOnInit(): void {
    this.getEncapsulationByid()
    this.getzjArray()
    this.getfzArray()
    this.getproidArray()
    this.getckglyArray()
  }

  getEncapsulationByid() {
    this.adminService.getEncapsulationByid(this.id).then((data: any) => {
      if (data.msg == "ok") {
        this.e = data.obj
      } else {
        this.alertService.showError("根据id获取封装失败")
      }
    })
  }

  getfzArray() {
    this.authService.getMemberListByRole("0b6bf8e2cd764de7b8030d5b967e05a6").then((data: any) => {
      if (data.msg == "ok") {
        this.fzArray = data.list
      } else {
        this.alertService.showError("获取分装人员失败")
      }
    })
  }

  getckglyArray() {
    this.authService.getMemberListByRole("c8a04131ff4e440c80009d894c6c8b41").then((data: any) => {
      if (data.msg == "ok") {
        this.ckglyArray = data.list
      } else {
        this.alertService.showError("获取仓库管理员失败")
      }
    })
  }

  getproidArray() {
    this.adminService.getNzSelCateByTypeid("e4fbf24f284146beb852a297356ebefa").then((data: any) => {
      if (data.msg == "ok") {
        this.proidArray = data.list
      } else {
        this.alertService.showError("获取产品名称失败")
      }
    })
  }

  getzjArray() {
    this.authService.getMemberListByRole("8f716f753b494efea3b5e1de73f4a347").then((data: any) => {
      if (data.msg == "ok") {
        this.zjArray = data.list
      } else {
        this.alertService.showError("获取质检人员失败")
      }
    })
  }

  save() {
    this.adminService.saveEncapsulation(this.e).then((data: any) => {
      if (data.msg == "ok") {
        this.alertService.showSuccess("设置封装成功")
      } else {
        this.alertService.showError("设置封装失败")
      }
    })
  }
}
